package cn.edu.cqvie.netty.protobuf.server;

import cn.edu.cqvie.netty.protobuf.DataInfo;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import java.util.logging.SocketHandler;

public class TestServerHandler extends SimpleChannelInboundHandler<DataInfo.MyMesage> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, DataInfo.MyMesage msg) throws Exception {
//        System.out.println(msg.getName());
//        System.out.println(msg.getAge());
//        System.out.println(msg.getAddress());

        DataInfo.MyMesage.DataType dataType = msg.getDataType();
        if (dataType == DataInfo.MyMesage.DataType.PersonType) {
            DataInfo.Person person = msg.getPerson();

            System.out.println(person.getName());
            System.out.println(person.getAge());
            System.out.println(person.getAddress());

        } else if (dataType == DataInfo.MyMesage.DataType.DogType) {

            DataInfo.Dog dog = msg.getDog();

            System.out.println(dog.getName());
            System.out.println(dog.getAge());
        } else {

            DataInfo.Cat cat = msg.getCat();
            System.out.println(cat.getName());
        }


    }
}
